package web;

import java.util.Date;
import java.util.List;

import tool.DateUtils;
import vo.PaperType;
import business.PaperTypeService;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("unchecked")
public class PaperTypeAction implements Preparable {
	private PaperTypeService service;
	private List<PaperType> paperTypes;
	private String name;

	public String listPaperType() {
		this.paperTypes = service.getAll();
		return Action.SUCCESS;
	}

	public String add() {

		return listPaperType();
	}

	// 添加paper
	public String insertPaperType() {
		System.out.println("insert Paper type:" + name);
		PaperType paperType= new PaperType();
		paperType.setName(name);
		Date today = new Date();
		String createdAt = DateUtils.date2Str(today, "-");
		paperType.setCreatedAt(createdAt);
		service.insert(paperType);
		return "insertPaperType";
	}

	public List<PaperType> getPaperTypes() {
		return this.paperTypes;
	}

	public void prepare() throws Exception {
		// if (id != null)
		// employee = service.find(id);
	}

	public void setPaperTypeService(PaperTypeService service) {
		this.service = service;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}